//
//  YDCarBrandModel.m
//  YDTestDrive
//
//  Created by ios on 2017/2/16.
//  Copyright © 2017年 ios. All rights reserved.
//

#import "YDCarBrandModel.h"
#import "YDCarSeriesModel.h"

@implementation YDCarBrandModel

+ (instancetype)carBrandModelWithDictionary:(NSDictionary *)dic
{
    YDCarBrandModel *brandModel = [[YDCarBrandModel alloc] init];
    brandModel.brandName = [dic valueForKey:@"brandsName"];
    brandModel.brandId = [dic valueForKey:@"modelId"];
    brandModel.logoPath = [dic valueForKey:@"logoPath"];
    
    NSArray *carsDicArray = [dic valueForKey:@"cars"];
    
    if ([carsDicArray isKindOfClass:[NSArray class]]) {
        
        NSMutableArray *carsArray = [NSMutableArray array];
        for (NSDictionary *carSeriesDic in carsDicArray) {
            YDCarSeriesModel *carSeriesModel = [YDCarSeriesModel instanceWithDict:carSeriesDic];
            [carsArray addObject:carSeriesModel];
        }
        brandModel.carSeriesArray = [NSArray arrayWithArray:carsArray];
        brandModel.carCount = brandModel.carSeriesArray.count;
        brandModel.cellHeight = brandModel.carCount * kCarSeriesHeight + kCarBrandHeight + 5.0f;
    } else {
        brandModel.carSeriesArray = @[];
        brandModel.carCount = 0;
        brandModel.cellHeight = kCarBrandHeight + 5.0f;
    }
    
    return brandModel;
}


@end
